/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.DateFormatUtil;
import com.ruipengkj.commons.util.Util;
/**
 * 状态栏
 * */
public class RPStatusBar extends JPanel implements ActionListener{

	private static final long serialVersionUID = 1L;
	
	private JLabel username;//当前账号
	
	private JLabel systemTime;//系统时间
	
	private JLabel loginTime;//登陆时间
	
	private JLabel operator;//当前操作员
	private Timer timer;
	public RPStatusBar(){
		GridLayout grid=new GridLayout(1, 4,1,1);
		this.setLayout(grid);
		this.setBorder(BorderFactory.createBevelBorder(1));
		
		username=new JLabel("当前用户：");
		loginTime=new JLabel("登陆时间：");
		systemTime=new JLabel("当前系统时间：");
		operator=new JLabel("当前操作员：");
		
		username.setBorder(BorderFactory.createBevelBorder(1));
		loginTime.setBorder(BorderFactory.createBevelBorder(1));
		systemTime.setBorder(BorderFactory.createBevelBorder(1));
		operator.setBorder(BorderFactory.createBevelBorder(1));
		
		username.setFont(Util.FONT_PLAIN_13);
		loginTime.setFont(Util.FONT_PLAIN_13);
		systemTime.setFont(Util.FONT_PLAIN_13);
		operator.setFont(Util.FONT_PLAIN_13);
		this.add(username);
		this.add(loginTime);
		this.add(systemTime);
		this.add(operator);
		
		timer=new Timer(1000, this);
		timer.start();
		if(ApplicationContext.EMPLOYEE!=null){
			username.setText("当前用户："+ApplicationContext.EMPLOYEE.getUserName());
			loginTime.setText("登陆时间："+DateFormatUtil.formatF(new Date()));
			systemTime.setText("当前系统时间："+DateFormatUtil.formatF(new Date()));
		}
		if(ApplicationContext.ROLE!=null){
			operator.setText("当前操作员："+ApplicationContext.ROLE.getName());
		}
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		systemTime.setText("当前系统时间："+DateFormatUtil.formatF(new Date()));
	}
}
